// 模拟 API 响应数据
const mockData = {
  // 流程定义列表
  'process-definition': {
    total: 3,
    data: [
      {
        id: 'PD1001',
        key: 'leave-process',
        name: '请假申请流程',
        version: 1,
        deploymentId: 'D1001',
        deploymentTime: '2023-10-01 10:00:00',
        suspended: false
      },
      {
        id: 'PD1002',
        key: 'expense-process',
        name: '报销申请流程',
        version: 2,
        deploymentId: 'D1002',
        deploymentTime: '2023-10-02 11:00:00',
        suspended: true
      },
      {
        id: 'PD1003',
        key: 'purchase-process',
        name: '采购申请流程',
        version: 1,
        deploymentId: 'D1003',
        deploymentTime: '2023-10-03 09:00:00',
        suspended: false
      }
    ]
  },
  
  // 流程实例列表
  'process-instance': {
    total: 3,
    data: [
      {
        id: 'PI1001',
        processDefinitionName: '请假申请流程',
        businessKey: 'LEAVE-2023001',
        startTime: '2023-10-01 09:00:00',
        suspended: false
      },
      {
        id: 'PI1002',
        processDefinitionName: '报销申请流程',
        businessKey: 'EXPENSE-2023001',
        startTime: '2023-10-02 10:00:00',
        suspended: true
      },
      {
        id: 'PI1003',
        processDefinitionName: '采购申请流程',
        businessKey: 'PURCHASE-2023001',
        startTime: '2023-10-03 11:00:00',
        suspended: false
      }
    ]
  },
  
  // 任务列表
  'task': {
    todo: {
      total: 2,
      data: [
        {
          id: 'T1001',
          name: '部门经理审批',
          processName: '请假申请流程',
          createTime: '2023-10-01 09:00:00',
          assignee: '张三',
          priority: 50
        },
        {
          id: 'T1002',
          name: '财务审批',
          processName: '报销申请流程',
          createTime: '2023-10-02 10:00:00',
          assignee: '李四',
          priority: 80
        }
      ]
    },
    claim: {
      total: 1,
      data: [
        {
          id: 'T1003',
          name: '总经理审批',
          processName: '采购申请流程',
          createTime: '2023-10-03 11:00:00',
          assignee: null,
          priority: 30
        }
      ]
    },
    done: {
      total: 1,
      data: [
        {
          id: 'T1004',
          name: 'HR审批',
          processName: '请假申请流程',
          createTime: '2023-09-30 08:00:00',
          assignee: '王五',
          priority: 50
        }
      ]
    }
  },
  
  // 仪表盘统计数据
  'dashboard/stats': {
    processDefinitions: 156,
    processInstances: 78,
    tasks: 42,
    historyProcesses: 324
  },
  
  // 仪表盘活动数据
  'dashboard/activities': [
    {
      processName: '请假申请流程',
      activityName: '部门经理审批',
      assignee: '张三',
      startTime: '2023-10-01 09:12:34',
      endTime: '2023-10-01 10:12:34',
      duration: '1小时0分钟'
    },
    {
      processName: '报销申请流程',
      activityName: '财务审批',
      assignee: '李四',
      startTime: '2023-10-01 11:22:33',
      endTime: '2023-10-01 11:45:22',
      duration: '22分钟49秒'
    },
    {
      processName: '采购申请流程',
      activityName: '总经理审批',
      assignee: '王五',
      startTime: '2023-10-02 08:12:34',
      endTime: '2023-10-02 14:12:34',
      duration: '6小时0分钟'
    }
  ]
}

/**
 * 模拟 API 请求
 * @param {string} url - 请求 URL
 * @param {Object} params - 请求参数
 * @returns {Promise} - 返回 Promise 对象
 */
export const mockRequest = (url, params = {}) => {
  return new Promise((resolve) => {
    console.log(`Mock API 请求: ${url}`, params)
    
    // 延迟响应，模拟网络请求
    setTimeout(() => {
      // 提取 URL 路径
      const path = url.split('?')[0]
      
      // 处理任务类型
      if (path === '/task') {
        const type = params.type || 'todo'
        resolve({
          code: 200,
          data: mockData['task'][type]
        })
        return
      }
      
      // 处理其他路径
      if (mockData[path.replace('/', '')]) {
        resolve({
          code: 200,
          data: mockData[path.replace('/', '')]
        })
        return
      }
      
      // 未找到数据
      resolve({
        code: 404,
        message: '未找到数据'
      })
    }, 300)
  })
}

export default { mockRequest } 